#!/usr/bin/env python
# -*- coding: utf-8 -*-

__author__ = "Mark Perry"
__license__ = "GPLv2"

from subprocess import *
import os,sys, shutil
import random
from stat import ST_SIZE

import wikicrm

# command line arguments
commands = {}
for i in sys.argv[1:]:
    commands[i] = True

def remove(path):
    if os.path.exists(path): os.system('rm -r ' + path)
 
if commands.get('-d'):
    if os.path.exists("articles.csv"): os.remove("articles.csv")
    remove("/media/sdd1/crm")
    remove("/media/sdd1/crmhtml")
    remove("wiki/public/js")
    remove("wiki/public/delimited")

wcrm = wikicrm.WikiCRM()

"""
i = 765     #abortion
#i = 44848   #edward
f = '/media/disk/wikidiff/%s/%s.bz2' % (int(i/100000), i)
if os.path.exists(f):
    p1 = Popen(["bzcat",f], stdout=PIPE)
    wcrm.main(p1.stdout)
    p1.stdout.close()
"""
while True:
    i = random.randint(0,1000000)
    f = '/media/disk/wikidiff/%s/%s.bz2' % (int(i/100000), i)
    if os.path.exists(f):
        print f
        p1 = Popen(["bzcat",f], stdout=PIPE)
        wcrm.main(p1.stdout)
        p1.stdout.close()

